#!/bin/sh

# Primitivni utilitka, ktera dela ze SRT / AP souboru (vystup programu muniphot 
# od Filipa Hrocha) soubory TAB, tedy lokalni katalogy TST (neboli tab table), 
# ktere umi nacist napriklad gaia.
# 2001 Jan Strobl. Hey, it's free!!! :-)

if [ $# = 0 ]; then
    echo "usage: $0 <input-file.SRT> [<output-file.tab>]" 1>&2
    exit 1
fi

infile="$1"
outfile="$2"


if [ $# = 2 ]; then
    echo "\
# Created by str2tab
id_col: 0
x_col: 1
y_col: 2
symbol:         {XPOS YPOS mag2} {circle {} {} {} {} {}} {{ 25/(\$mag2 - 6)} {}}
#
ID	XPOS	YPOS	mag1	mag2	mag3	mag4	mag5	mag6	mag7	mag8	mag9	mag10	mag11	mag12
--	----	----	----	----	----	----	----	----	----	----	----	-----	-----	-----" > $outfile
    cat $infile | 
	tr -s [:blank:] | 
        colrm 1 1 | 
        tr [:blank:] "\t" | 
        tail +4 | 
        awk '{if(i%3 == 0)print; i++;}' >> $outfile
	exit 0
fi

echo "\
# Created by str2tab
id_col: 0
x_col: 1
y_col: 2
symbol:         {XPOS YPOS mag2} {circle {} {} {} {} {}} {{ 25/(\$mag2 - 6)} {}}
#
ID	XPOS	YPOS	mag1	mag2	mag3	mag4	mag5	mag6	mag7	mag8	mag9	mag10	mag11	mag12
--	----	----	----	----	----	----	----	----	----	----	----	-----	-----	-----"

cat $infile | 
    tr -s [:blank:] | 
    colrm 1 1 | 
    tr [:blank:] "\t" | 
    tail +4 | 
    awk '{if(i%3 == 0)print; i++;}'
